<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>解构赋值</title>
</head>
<body>
    <div></div>
    <script>

        //1、对象解构赋值
        let {a,b}={a:1,b:2};
        console.log(a,b)//1,2
        //2、如果解构不成功为undefined
        let {c} = {a:1,b:2};
        console.log(c)//undefined

        //3、修改名称
        let {a3:name} = {a3:'aaa',b3:'bbb'}
        console.log(name)//aaa打印的是name就是a3的值
        
        // let {a,b}={a:1,b:2};
        // //其实上面是简写等价于
        // let {a:a,b:b} = {a:1,b:2}

        //4、属性解构
        let arr = [0,1,2,3]
        console.log(arr)
        let {length} = arr
        //let length = arr.length
        console.log(length)//4,相当于arr里面有一个length的属性
        //let{length} = {length:4}

        //还有一种用法
        let {0:a4,[arr.length-1]:b4} = arr
        console.log(a4,b4)//0,3
    </script>
</body>
</html>